Parsing an header with two different version [ID3] avoiding code duplication?

Posted by user66141 on Programmers See other posts from Programmers or by user66141
Published on 2012-09-25T16:14:58Z Indexed on 2012/09/25 21:49 UTC
Read the original article Hit count: 237

I really hope you could give me some interesting viewpoints for my situation,

my ways to approach my issue are not to my liking .

I am writing an mp3 parser , starting with an ID3v2 parser .

Right now I`m working on the extended header parsing , my issue is that the optional header is defined differently in version 2.3 and 2.4 of the tag .

The 2.3 version optional header is defined as follows :

struct ID3_3_EXTENDED_HEADER{
DWORD dwExtHeaderSize;          //Extended header size (either 6 or 8 bytes , excluded)
WORD  wExtFlags;                //Extended header flags
DWORD dwSizeOfPadding;          //Size of padding (size of the tag excluding the frames and headers)
};

While the 2.4 version is defined :

struct ID3_4_EXTENDED_HEADER{
DWORD dwExtHeaderSize;          //Extended header size (synchsafe int)
BYTE  bNumberOfFlagBytes;       //Number of flag bytes
BYTE  bFlags;                   //Flags
};

How could I parse the header while minimizing code duplication ?

Using two different functions to parse each version sounds less great ,

using a single function with a different flow for each occasion is similar ,

any good practices for this kind of issues ? any tips for avoiding code duplication ?

anything would be great .

© Programmers or respective owner

Related posts about programming-practices

Related posts about c